﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
namespace test14 {
    public class playercontroller : MonoBehaviour
    {
        private Rigidbody rb;//刚体
        public LayerMask ground;//地面层
        private NavMeshAgent nav;//导航代理
        private Vector3 targetPosition;//目标点
        public int count = 5;//剩余数量
      
        // Start is called before the first frame update
        void Start()
        {
            rb = GetComponent<Rigidbody>();
            nav = GetComponent<NavMeshAgent>();
           
        }

        // Update is called once per frame
        void Update()
        {
            getPoint(); 
        }
          /// <summary>
          /// 得到点击的点并移动
          /// </summary>
        private void getPoint()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100,ground))
                {
                    targetPosition = hit.point;
                    nav.destination = targetPosition;
                }
            }
        }
    }
}
